package jmine.tec.aom.validator;

import jmine.tec.aom.builder.PropertyTypeBuilder;
import jmine.tec.aom.domain.PropertyType;
import jmine.tec.test.junit4.DBEnv;
import jmine.tec.test.junit4.DBTestCase;

import org.junit.Test;

import bancosys.tec.persist.validator.ValidationException;

/**
 * @author jrenaut
 */
@DBEnv(refdb = "jmine-tec-aom-db-test.xml", spring = "jmine-tec-aom-test.xml")
public class PropertyTypeValidatorShould extends DBTestCase {

    @Test(expected = ValidationException.class)
    public void reportErrorOnInaccessibleClass() {
        PropertyType pt = PropertyTypeBuilder.aPropertyType().build();
        pt.setPropertyValueClass("class.name.clearly.does.not.Exist");
        pt.getPersister().save();
    }

    @Test(expected = ValidationException.class)
    public void reportErrorOnInvalidPropertyValueClass() {
        PropertyType pt = PropertyTypeBuilder.aPropertyType().build();
        pt.setPropertyValueClass(String.class.getName());
        pt.getPersister().save();
    }

    @Test
    public void reportNoErrorOnCorrectEntity() {
        PropertyTypeBuilder.aPropertyType().save();
    }

}
